/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.unice.miage.oobdoo.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author remi
 */
@Entity
@XmlRootElement
public class Photo implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    private String pathFile;
    private String pathThumbHome;
    private String pathThumbList;
    private String pathThumbPhoto;
    private String nom;
    private String description;

    @ManyToOne
    private Album album;

    @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
    private Collection<Commentaire> commentaires;

    public Photo() {}

    public Photo(Album album, String nom, String description, String pathFile, String pathThumbHome, String pathThumbList, String pathThumbPhoto) {
        this.album = album;
        this.nom = nom;
        this.description = description;
        this.pathFile = pathFile;
        this.pathThumbHome = pathThumbHome;
        this.pathThumbList = pathThumbList;
        this.pathThumbPhoto = pathThumbPhoto;
        this.commentaires = new ArrayList<Commentaire>();
    }

    public Album getAlbum() {
        return album;
    }

    public Collection<Commentaire> getCommentaires() {
        return commentaires;
    }

    public ArrayList<Commentaire> getCommentairesList()
    {
        ArrayList<Commentaire> list = new ArrayList<Commentaire>();

        for(Commentaire c : this.commentaires)
        {
            list.add(c);
        }

        Collections.sort(list);

        return list;
    }

    public void addCommentaire(Commentaire c)
    {
        this.commentaires.add(c);
    }

    public void setAlbum(Album album) {
        this.album = album;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getPathFile() {
        return pathFile;
    }

    public void setPathFile(String pathFile) {
        this.pathFile = pathFile;
    }

    public String getPathThumbHome() {
        return pathThumbHome;
    }

    public void setPathThumbHome(String pathThumbHome) {
        this.pathThumbHome = pathThumbHome;
    }

    public String getPathThumbList() {
        return pathThumbList;
    }

    public void setPathThumbList(String pathThumbList) {
        this.pathThumbList = pathThumbList;
    }

    public String getPathThumbPhoto() {
        return pathThumbPhoto;
    }

    public void setPathThumbPhoto(String pathThumbPhoto) {
        this.pathThumbPhoto = pathThumbPhoto;
    }

}
